package com.flower.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.flower.domain.entity.Category;
import com.flower.domain.entity.Product;
import com.flower.service.CategoryService;
import com.flower.mapper.CategoryMapper;
import com.flower.service.ProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 86178
* @description 针对表【category(商品分类表)】的数据库操作Service实现
* @createDate 2025-03-04 12:26:59
*/
@Service
@RequiredArgsConstructor
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
    implements CategoryService{

    private final ProductService productService;

    @Override
    public void removeByIdsWithProduct(List<Integer> ids) {
        // 删除分类前先改变当前分类下的所有商品的分类
        productService.lambdaUpdate()
                .in(Product::getCategoryId, ids)
                .set(Product::getCategoryId, 0)
                .update();
        // 删除分类
        this.removeByIds(ids);
    }
}




